import cv2
import numpy as np

class Noise:
    def __init__(self):
        pass
    
    def __call__(self, src, sigma=1.0):

        noise = np.random.normal(loc=0.0, scale=sigma, size=src.shape)

        dst = (src + noise).clip(min=0, max=255).astype('uint8')

        return dst


if __name__ == '__main__':
    SRC = cv2.imread('peppers-bw.bmp', cv2.IMREAD_GRAYSCALE)

    def show(winname, img):
        cv2.imshow(winname, img)
        cv2.resizeWindow(winname, 512, 512)
        cv2.waitKey(1)

    show('ORIGIN', SRC)

    show('NOISE', Noise()(SRC, sigma=2.0))

    cv2.waitKey(0)